<template>
  <div class="product-list">
    <img
      src="../../assets/logo.png"
      alt=""
      style="width: 100px; height: 50px; position: absolute; top: 2%; right: 5%"
    />
    <h1 style="margin-bottom: 20px">文创产品:</h1>
    <div class="product-container">
      <div
        class="product-card"
        v-for="product in products"
        :key="product.id"
        @click="goToDetail(product.detail_link)"
      >
        <div class="product-image">
          <img :src="product.image" alt="Product Image" />
        </div>
        <div class="product-details">
          <p class="product-name">{{ product.name }}</p>
          <p class="price">价格: {{ product.price }}</p>
          <p class="discounted-price">优惠价: {{ product.discounted_price }}</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { fetchProducts } from "../../api/product";

export default {
  data() {
    return {
      products: [],
    };
  },
  mounted() {
    fetchProducts()
      .then((response) => {
        this.products = response;
      })
      .catch((error) => {
        console.error("Error fetching products:", error);
      });
  },
  methods: {
    goToDetail(link) {
      window.open(link, "_blank");
    },
  },
};
</script>

<style scoped>
.product-list {
  width: 100vw;
  height: 100vh;
  padding: 20px;
  background: url(../../assets/bg.jpg) no-repeat;
  box-sizing: border-box;
  overflow: auto;
}
.product-container {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
}

.product-card {
  width: 250px;
  height: 350px;
  margin-bottom: 20px;
  background-color: #fff;
  border: 1px solid #ddd;
  border-radius: 5px;
  overflow: hidden;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  transition: box-shadow 0.3s ease;
  cursor: pointer;
}

.product-card:hover {
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.product-image {
  width: 100%;
  height: 200px;
  overflow: hidden;
}

.product-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.product-details {
  padding: 15px;
  height: 100px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.product-name {
  font-size: 18px;
  font-weight: bold;
  margin-bottom: 10px;
}

.price {
  color: #009688;
  margin-bottom: 5px;
}

.discounted-price {
  color: #f56c6c;
  margin-bottom: 5px;
}
</style>
